<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>登录页示例</title>
	<script src="/static/js/jquery.js"></script>
</head>
<body>
<div style="margin: 10px auto;text-align: center">
	<div><label for="username">用户名：</label><input type="text" id="username"></div>
	<div><label for="password">密&emsp;码：</label><input type="password" id="password"></div>
	<div>
		<button id="goLogin">登录</button>
		<button id="goRegister">注册</button>
	</div>
</div>
<script>
	$('#goLogin').click(function (){
        let username=$('#username').val(),
        password=$('#password').val();
        $.ajax({
            url: '/index/login',
            data: {username:username,password:password},
            type: 'post',
            dataType: 'json',
            success: function (data) {
				if(!data.code){
                    alert(data.msg);
                    return;
				}
                alert('登录成功');
            },
            error: function () {
                alert('连接出错')
            }
        });
	})


    $('#goRegister').click(function (){
        let username=$('#username').val(),
            password=$('#password').val();
        $.ajax({
            url: '/index/register',
            data: {username:username,password:password},
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if(!data.code){
                    alert(data.msg)
					return;
                }
                alert('注册成功');
            },
            error: function () {
                alert('连接出错')
            }
        });
    })
</script>
</body>
</html>